import request from '../utils/request'
import { ip } from '../utils/getinfo'
import loginstore from '@/store/userlogin.js'
import { parse } from 'path'
const api={
	userzc:"/user/zc",
	userlogin:"/user/login",
	dslogin:"/user/sdlogin",
	userfind:"/user/",
	userupdateimg:'/user/updateimage',
	useruodatename:'/user/updatename',
	userallsum:'/user/userallsum',
	hoseadd:"/hose/add",
	hoseaddress:'/hose/address',
	hoseseach:'/hose/seach',
	hosefindid:"/hose/",
	hoselove:"/hose/love/",
	hoseleavelove:"/hose/leavelove/",
	hosealllove:"/hose/allloves",
	userlookhistroy:"/hose/histroy/",
	allhistory:"/hose/allhistory/",
    delehistroy	:'/hose/delehistroy/',
	myselfhose:"/hose/myselfhose",
	okhose:"/hose/okhose/",
	hosedown:"/hose/hosedown/",
	hoseup:"/hose/hoseup/",
	baibai:'/user/baibai',
	getunlinedata:"/user/getunlinedata"
}
export const getunlinedata=()=>request({url:api.getunlinedata,method:"post"})
export const useruodatename=(name)=>request({url:api.useruodatename,data:{name},method:"post"})
export const useruserallsum=()=>request({url:api.userallsum,method:"post"})
export const userbaibai=()=>request({url:api.baibai,method:"post"})
export const userupdateimg =(img)=>{
	  return new Promise((res,rej)=>{
		  const usestore=loginstore()
		    uni.uploadFile({
				url:ip+api.userupdateimg,
				filePath:img,
				name:"img",
				header:{
					token:usestore.token||""
				},
				success(e) {
					if(e.statusCode==401){
						  uni.showToast({
						  	title:"请重新登录！",
						  	icon:"none",
							success() {
								setTimeout(()=>{
									uni.reLaunch({
										url:"/pages/login/login"
									})
								},1000)
							}
						  })
					}
					res(JSON.parse(e.data))
				},
				fail(err) {
					console.log(err)
					rej(err)
				}
			})
	  })
}
export const userfind=id=>request({url:api.userfind+id})
export const getfindid=id=>request({url:api.hosefindid+id})
export const getsearchdata=(keyword,limit,offset)=>request({url:api.hoseseach,data:{keyword,limit,offset}})
export const gethoseaddress=(address)=>request({url:api.hoseaddress,data:{...address},method:"post"})
export const getuserzc=(username,password)=>request({url:api.userzc,data:{username,password}})
export const getuserlogin=(username,password)=>request({url:api.userlogin,data:{username,password}})
export const getdslogin=(code,provider,userinfo="")=>request({url:api.dslogin,data:{code,provider,userinfo},method:"post"})
export const sendhosedata=({img,...data})=>{
	const usestore=loginstore()
	const filePath=img[0]
	     return new Promise((res,rej)=>{
			      uni.uploadFile({
					  url:ip+api.hoseadd,
					  filePath,
					  name:"img",
					  formData:data,
					  header:{
						  token:usestore.token||""
					  },
					  success(e){
						  if(e.statusCode==401){
							  uni.showToast({
							  	title:"请重新登录！",
							  	icon:"none",
								success() {
									setTimeout(()=>{
										uni.reLaunch({
											url:"/pages/login/login"
										})
									},1000)
								}
							  })
						  }
						  res(JSON.parse(e.data))
					  },
					  fail(err) {
						console.log(err)
					  	rej(err)
					  }
				  })
		 })
}
export const gethoselove=id=>request({url:api.hoselove+id})
export const gethosealllove=()=>request({url:api.hosealllove,method:"post"})
export const gethoseleavelove=(hoseid,userid)=>request({url:api.hoseleavelove+hoseid+'/'+userid})
export const getuserlookhistroy=(hoseid)=>request({url:api.userlookhistroy+hoseid})
export const getallhistory=(limit,offset)=>request({url:api.allhistory+limit+'/'+offset,method:"post"})
export const getdelehistroy=(id)=>request({url:api.delehistroy+id})
export const getmyselfhose=()=>request({url:api.myselfhose,method:"post"})
export const getokhosee=(hoseid)=>request({url:api.okhose+hoseid,method:"post"})
export const gethosedown=(hoseid)=>request({url:api.hosedown+hoseid,method:"post"})
export const gethoseup=(hoseid)=>request({url:api.hoseup+hoseid,method:"post"})



